<?php
namespace app\admin\controller\v1;

use app\admin\validate\CreateSource;
use app\admin\validate\IDMustBePositiveInt;
use app\lib\exception\NotFoundException;
use think\Controller;
use app\common\model\Source as SourceModel;
use think\Db;

class Source extends BaseController
{
    public function getAll()
    {
        $auth_list = SourceModel::getAll();
        return successReturn($auth_list);
    }
    public function deleteOne($id){
        $auth = SourceModel::get($id);
        if(!$auth) throw (new NotFoundException());
        $res = SourceModel::deleteOne($id);
        return successReturn();
    }
    public function getAuthListByAdminId($id){
//        $roles = ;
    }
    public function createOne(){
        //验证
        (new CreateSource())->goCheck();
        $data = input('post.');
        $data['permissions'] = implode('|',$data['permissions']);
        SourceModel::createOne($data);
        return successReturn();

    }
    public function updateOne($id){
        (new IDMustBePositiveInt())->goCheck();
        $data = input('put.');
        $data['permissions'] = implode('|',$data['permissions']);
        SourceModel::updateOne($id,$data);
        return successReturn();
    }
}
